/**
 * 
 */
package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.util.List;

import jmine.tec.report.cell.DataCell;
import jmine.tec.report.cell.FunctionDataCell;

/**
 * {@link FunctionDataCell} que faz o AND entre BooleanDataCell. Esta celula considera qualquer valor diferente de
 * {@link BooleanDataCell#TRUE} como falso. O valor default é <code>true</code>.
 * 
 * @author takeshi
 */
public final class BooleanANDFunctionDataCell extends AbstractFunctionDataCell implements FunctionDataCell, Serializable {

    /**
	 * 
	 */
    private static final long serialVersionUID = 8231573341568711780L;

    /**
     * Default private constructor
     */
    private BooleanANDFunctionDataCell() {
        super();
    }

    /**
     * LazyInitialization helper class
     */
    private static final class InstanceHolder {

        /**
         */
        private InstanceHolder() {
        }

        private static final BooleanANDFunctionDataCell INSTANCE = new BooleanANDFunctionDataCell();
    }

    /**
     * Returns the single instance of this class, lazy loading if necessary
     * 
     * @return the single instance
     */
    public static BooleanANDFunctionDataCell getInstance() {
        return InstanceHolder.INSTANCE;
    }

    /**
     * @param childCells the childCells
     * @return {@link DataCell}
     * @see br.com.maps.util.report.cell.FunctionDataCell#eval(java.util.List)
     */
    public DataCell eval(final List<? extends DataCell> childCells) {
        for (DataCell dataCell : childCells) {
            if (dataCell != BooleanDataCell.TRUE) {
                return BooleanDataCell.FALSE;
            }
        }
        return BooleanDataCell.TRUE;
    }

    /**
     * Implementation of {@link Serializable} to provide custom resolving mechanism while desserializing an object instance
     * 
     * @return the single instance
     */
    protected Object readResolve() {
        return getInstance();
    }
}
